package com.dotflat.check.repository;

import com.dotflat.check.domain.DeviceRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface DeviceRecordRepository extends JpaRepository<DeviceRecord, String>, JpaSpecificationExecutor<DeviceRecord> {


    @Query(value="SELECT type  FROM c_device_record where areaId = ?1  GROUP BY type",nativeQuery = true)
    List<Integer> getTypeList(String areaId);

    @Query(value="SELECT *  FROM c_device_record where areaId = ?1 and type = ?2  ORDER BY  created desc LIMIT 1",nativeQuery = true)
    DeviceRecord getNewest(String areaId,Integer type);
}
